using Masuit.Tools.Database;
using Masuit.Tools.Excel;
using Microsoft.AspNetCore.Mvc;
using System;
using System.ComponentModel;

namespace DateTime返回年月日.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
        [HttpGet]
        public Stream Download()
        {
            var list = new List<Person>() {
                new Person(){ Name="张三",Age =13,Gender="男"},
                new Person(){ Name="李四",Age =13,Gender="女"}
            };
            var stream = list.ToDataTable().ToExcel(""); //自定义列名导出
            return stream;
        }
    }
    public class Person
    {
        [Description("姓名")]
        public string Name { get; set; }
        [Description("年龄")]
        public int Age { get; set; }
        [Description("性别")]
        public string Gender { get; set; }

    }
}